package com.tnt.springbootrabbmitmq.provider.directexchange;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description 直连型交换机配置
 * @Author zhuangxl
 * @Date 2021-01-22 21:52
 */
@Configuration
public class DirectExchangeRabbitMqConfig {


    /**
     * @Description: 定义队列
     * @Author: zhuangxl
     * @Date: 21/1/22 22:16
     * @return: org.springframework.amqp.core.Queue
     **/
    @Bean
    public Queue directQueue(){

        return new Queue("directQueue", true, false, false);

    }

    /**
     * @Description: 定义交换机
     * @Author: zhuangxl
     * @Date: 21/1/22 22:17
     * @return: org.springframework.amqp.core.directexchange
     **/
    @Bean
    public DirectExchange directExchange(){

        return new DirectExchange("directExchange", true, false);

    }

    /**
     * @Description: 队列绑定到交换机上，并指定路由key.
     * @Author: zhuangxl
     * @Date: 21/1/22 22:22
     * @return: org.springframework.amqp.core.Binding
     **/
    @Bean
    Binding directBinding(){

        return BindingBuilder.bind(directQueue()).to(directExchange()).with("directRouting");

    }


}
